using System;
using System.Runtime.InteropServices;

public class ConsoleShow
{
    [DllImport("kernel32.dll")]
    private static extern bool AllocConsole();
    [DllImport("kernel32.dll")]
    private static extern bool FreeConsole();
    [DllImport("kernel32.dll",
        EntryPoint = "GetStdHandle",
        SetLastError = true,
        CharSet = CharSet.Auto,
        CallingConvention = CallingConvention.StdCall)]
    private static extern IntPtr GetStdHandle(int nStdHandle);

    private const int STD_OUTPUT_HANDLE = -11;
    public static void SetOutput()
    {
        AllocConsole();

        //IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
        //SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true);
        //FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write);
        //Encoding encoding = System.Text.Encoding.GetEncoding(Console.OutputEncoding.CodePage);
        //StreamWriter standardOutput = new StreamWriter(fileStream, encoding);
        //standardOutput.AutoFlush = true;
        //Console.SetOut(standardOutput);

        Console.ForegroundColor = ConsoleColor.Green;
    }
    public static void CloseOutput()
    {
        FreeConsole();
    }
}